﻿'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose:
'
'
'*******************************************************************

Imports System
Imports System.ComponentModel
Imports System.Management
Imports System.Management.Instrumentation
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports Microsoft.VisualBasic

Imports System.Windows.Forms

Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging

Public Class IcmpResults

    Public Class IcmpStepPingResult


        Public dtSteppedPing As System.Data.DataTable

        Public Structure stcStepPingResult
            Public spPacketSize As String
            Public spPingAddress As String
            Public spTotDelay As Int32
            Public spMaxDelay As Int32
            Public spMinDelay As Int32
            Public spAvgDelay As Int32
            Public spDel10 As Int32
            Public spDel01 As Int32
            Public spDel02 As Int32
            Public spDel03 As Int32
            Public spDel04 As Int32
            Public spDel05 As Int32
            Public spDel06 As Int32
            Public spDel07 As Int32
            Public spDel08 As Int32
            Public spDel09 As Int32
            Public spErrorCt As Int16
            Public spDate As Date
        End Structure


        '
        ' we go through this pain so that we can move the stuff
        ' to the report viewer
        '

        Private m_spPingAddress As String
        Public Property spPingAddress() As String
            Get
                spPingAddress = m_spPingAddress
            End Get
            Set(ByVal value As String)
                m_spPingAddress = value
            End Set
        End Property

        Private m_spPacketSize As String
        Public Property spPacketSize() As String
            Get
                Return m_spPacketSize
            End Get
            Set(ByVal value As String)
                m_spPacketSize = value
            End Set
        End Property

        Private m_spTotDelay As Int32
        Public Property spTotDelay() As Int32
            Get
                spTotDelay = m_spTotDelay
            End Get
            Set(ByVal value As Int32)
                m_spTotDelay = value
            End Set
        End Property

        Private m_spMaxDelay As Int32
        Public Property spMaxDelay() As Int32
            Get
                spMaxDelay = m_spMaxDelay
            End Get
            Set(ByVal value As Int32)
                m_spMaxDelay = value
            End Set
        End Property

        Private m_spMinDelay As Int32
        Public Property spMinDelay() As Int32
            Get
                spMinDelay = m_spMinDelay
            End Get
            Set(ByVal value As Int32)
                m_spMinDelay = value
            End Set
        End Property

        Private m_spAvgDelay As Int32
        Public Property spAvgDelay() As Int32
            Get
                spAvgDelay = m_spAvgDelay
            End Get
            Set(ByVal value As Int32)
                m_spAvgDelay = value
            End Set
        End Property

        Private m_spDel01 As Int32
        Public Property spDel01() As Int32
            Get
                spDel01 = m_spDel01
            End Get
            Set(ByVal value As Int32)
                m_spDel01 = value
            End Set
        End Property

        Private m_spDel02 As Int32
        Public Property spDel02() As Int32
            Get
                spDel02 = m_spDel02
            End Get
            Set(ByVal value As Int32)
                m_spDel02 = value
            End Set
        End Property

        Private m_spDel03 As Int32
        Public Property spDel03() As Int32
            Get
                spDel03 = m_spDel03
            End Get
            Set(ByVal value As Int32)
                m_spDel03 = value
            End Set
        End Property

        Private m_spDel04 As Int32
        Public Property spDel04() As Int32
            Get
                spDel04 = m_spDel04
            End Get
            Set(ByVal value As Int32)
                m_spDel04 = value
            End Set
        End Property

        Private m_spDel05 As Int32
        Public Property spDel05() As Int32
            Get
                spDel05 = m_spDel05
            End Get
            Set(ByVal value As Int32)
                m_spDel05 = value
            End Set
        End Property

        Private m_spDel06 As Int32
        Public Property spDel06() As Int32
            Get
                spDel06 = m_spDel06
            End Get
            Set(ByVal value As Int32)
                m_spDel06 = value
            End Set
        End Property

        Private m_spDel07 As Int32
        Public Property spDel07() As Int32
            Get
                spDel07 = m_spDel07
            End Get
            Set(ByVal value As Int32)
                m_spDel07 = value
            End Set
        End Property

        Private m_spDel08 As Int32
        Public Property spDel08() As Int32
            Get
                spDel08 = m_spDel08
            End Get
            Set(ByVal value As Int32)
                m_spDel08 = value
            End Set
        End Property

        Private m_spDel09 As Int32
        Public Property spDel09() As Int32
            Get
                spDel09 = m_spDel09
            End Get
            Set(ByVal value As Int32)
                m_spDel09 = value
            End Set
        End Property

        Private m_spDel10 As Int32
        Public Property spDel10() As Int32
            Get
                spDel10 = m_spDel10
            End Get
            Set(ByVal value As Int32)
                m_spDel10 = value
            End Set
        End Property

        Private m_spErrorCt As Int16
        Public Property spErrorCt() As Int16
            Get
                spErrorCt = m_spErrorCt
            End Get
            Set(ByVal value As Int16)
                m_spErrorCt = value
            End Set
        End Property

        Private m_spDate As Date
        Public Property spDate() As Date
            Get
                spDate = m_spDate
            End Get
            Set(ByVal value As Date)
                m_spDate = value
            End Set
        End Property

        Private m_colStepPingResult As Collection
        Property colStepPingResults() As Collection
            Get
                If m_colStepPingResult Is Nothing Then
                    m_colStepPingResult = New Collection
                End If
                colStepPingResults = m_colStepPingResult
            End Get
            Set(ByVal value As Collection)
                m_colStepPingResult = value
            End Set
        End Property

        Public Sub Add(ByVal newStepPingResult As stcStepPingResult)
            colStepPingResults.Add(newStepPingResult)
        End Sub

        Public Function Count() As Int16
            Return colStepPingResults.Count
        End Function

        Public Sub Clear()
            colStepPingResults.Clear()
        End Sub

        Public Sub New()
            colStepPingResults = New Collection
            dtSteppedPing = New System.Data.DataTable
            CreateTableColumns(dtSteppedPing)
            spDate = Now
        End Sub

        '
        '
        '
        Public Sub CreateTableColumns(ByRef tempTable As DataTable)


            tempTable.TableName = "tblStepPingResults"

            Try

                Dim dcspPingAddress As New System.Data.DataColumn
                dcspPingAddress.ColumnName = "spPingAddress"
                dcspPingAddress.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dcspPingAddress)

                Dim dcspPacketSize As New System.Data.DataColumn
                dcspPacketSize.ColumnName = "spPacketSize"
                dcspPacketSize.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dcspPacketSize)

                Dim dcspTotDelay As New System.Data.DataColumn
                dcspTotDelay.ColumnName = "spTotDelay"
                dcspTotDelay.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspTotDelay)

                Dim dcspMaxDelay As New System.Data.DataColumn
                dcspMaxDelay.ColumnName = "spMaxDelay"
                dcspMaxDelay.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspMaxDelay)

                Dim dcspMinDelay As New System.Data.DataColumn
                dcspMinDelay.ColumnName = "spMinDelay"
                dcspMinDelay.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspMinDelay)

                Dim dcspAvgDelay As New System.Data.DataColumn
                dcspAvgDelay.ColumnName = "spAvgDelay"
                dcspAvgDelay.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspAvgDelay)

                Dim dcspDel01 As New System.Data.DataColumn
                dcspDel01.ColumnName = "spDel01"
                dcspDel01.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel01)

                Dim dcspDel02 As New System.Data.DataColumn
                dcspDel02.ColumnName = "spDel02"
                dcspDel02.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel02)

                Dim dcspDel03 As New System.Data.DataColumn
                dcspDel03.ColumnName = "spDel03"
                dcspDel03.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel03)

                Dim dcspDel04 As New System.Data.DataColumn
                dcspDel04.ColumnName = "spDel04"
                dcspDel04.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel04)

                Dim dcspDel05 As New System.Data.DataColumn
                dcspDel05.ColumnName = "spDel05"
                dcspDel05.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel05)

                Dim dcspDel06 As New System.Data.DataColumn
                dcspDel06.ColumnName = "spDel06"
                dcspDel06.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel06)

                Dim dcspDel07 As New System.Data.DataColumn
                dcspDel07.ColumnName = "spDel07"
                dcspDel07.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel07)

                Dim dcspDel08 As New System.Data.DataColumn
                dcspDel08.ColumnName = "spDel08"
                dcspDel08.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel08)

                Dim dcspDel09 As New System.Data.DataColumn
                dcspDel09.ColumnName = "spDel09"
                dcspDel09.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel09)

                Dim dcspDel10 As New System.Data.DataColumn
                dcspDel10.ColumnName = "spDel10"
                dcspDel10.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcspDel10)

                Dim dcspErrorCt As New System.Data.DataColumn
                dcspErrorCt.ColumnName = "spErrorCt"
                dcspErrorCt.DataType = Type.GetType("System.Int16")
                tempTable.Columns.Add(dcspErrorCt)

                Dim dcspDate As New System.Data.DataColumn
                dcspDate.ColumnName = "spDate"
                dcspDate.DataType = Type.GetType("System.DateTime")
                tempTable.Columns.Add(dcspDate)

            Catch sql As SqlException
                '********* visio snippet vb.net vis0057vb ******************
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
                If (rethrow) Then
                    Throw
                End If


            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try



        End Sub

        '
        ' copy the collection of stepped ping results to the output table
        '
        Public Sub loadTable(ByRef tempTable As System.Data.DataTable)

            Try

                Dim stcResult As stcStepPingResult
                Dim m_dr As DataRow
                For Each stcResult In colStepPingResults
                    With stcResult
                        m_dr = tempTable.NewRow
                        m_dr.Item("spPingAddress") = .spPingAddress
                        m_dr.Item("spPacketSize") = .spPacketSize
                        m_dr.Item("spTotDelay") = .spTotDelay
                        m_dr.Item("spMaxDelay") = .spMaxDelay
                        m_dr.Item("spMinDelay") = .spMinDelay
                        m_dr.Item("spAvgDelay") = .spAvgDelay
                        m_dr.Item("spDel01") = .spDel01
                        m_dr.Item("spDel02") = .spDel02
                        m_dr.Item("spDel03") = .spDel03
                        m_dr.Item("spDel04") = .spDel04
                        m_dr.Item("spDel05") = .spDel05
                        m_dr.Item("spDel06") = .spDel06
                        m_dr.Item("spDel07") = .spDel07
                        m_dr.Item("spDel08") = .spDel08
                        m_dr.Item("spDel09") = .spDel09
                        m_dr.Item("spDel10") = .spDel10
                        m_dr.Item("spErrorCt") = .spErrorCt
                        m_dr.Item("spDate") = Now
                        tempTable.Rows.Add(m_dr)
                    End With
                Next stcResult


            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub

        Public Sub buildReportTable()

            dtSteppedPing = Nothing
            dtSteppedPing = New System.Data.DataTable
            CreateTableColumns(dtSteppedPing)
            loadTable(dtSteppedPing)

        End Sub

        '
        '
        '
        Public Sub initStepPingProperties()
            m_spAvgDelay = 0
            m_spDate = Now
            m_spDel01 = 0
            m_spDel02 = 0
            m_spDel03 = 0
            m_spDel04 = 0
            m_spDel05 = 0
            m_spDel06 = 0
            m_spDel07 = 0
            m_spDel08 = 0
            m_spDel09 = 0
            m_spDel10 = 0
            m_spMaxDelay = 0
            m_spMinDelay = 0
            m_spTotDelay = 0
            m_spPacketSize = "0"
            m_spPingAddress = ""
        End Sub

        '
        '
        '
        Public Sub addStepPingResultToCol()

            Dim stcResult As stcStepPingResult = New stcStepPingResult
            With stcResult
                .spPingAddress = spPingAddress
                .spPacketSize = spPacketSize
                .spTotDelay = spTotDelay
                .spMaxDelay = spMaxDelay
                .spMinDelay = spMinDelay
                .spAvgDelay = spAvgDelay
                .spDel01 = spDel01
                .spDel02 = spDel02
                .spDel03 = spDel03
                .spDel04 = spDel04
                .spDel05 = spDel05
                .spDel06 = spDel06
                .spDel07 = spDel07
                .spDel08 = spDel08
                .spDel09 = spDel09
                .spDel10 = spDel10
                .spErrorCt = spErrorCt
                m_colStepPingResult.Add(stcResult)
            End With


        End Sub

        '
        ' this moves the stepped ping results to the ping results datalistview control
        '
        Public Sub loadDlvSteppedPingResults _
                   (ByRef dlvControl As System.Windows.Forms.ListView, _
                    Optional ByVal dtTemp As System.Data.DataTable = Nothing)

            dlvControl.Clear()
            dlvControl.View = View.Details
            dlvControl.Columns.Clear()

            Try


                With dlvControl
                    .Columns.Add(New ColumnHeader)
                    .Columns(0).Text = "PacketSize"
                    .Columns.Add(New ColumnHeader)
                    .Columns(1).Text = "AvgDelay"
                    .Columns.Add(New ColumnHeader)
                    .Columns(2).Text = "MaxDelay"
                    .Columns.Add(New ColumnHeader)
                    .Columns(3).Text = "MinDelay"
                    .Columns.Add(New ColumnHeader)
                    .Columns(4).Text = "ErrorCt"
                    .Columns.Add(New ColumnHeader)
                    .Columns(5).Text = "del01"
                    .Columns.Add(New ColumnHeader)
                    .Columns(6).Text = "del02"
                    .Columns.Add(New ColumnHeader)
                    .Columns(7).Text = "del03"
                    .Columns.Add(New ColumnHeader)
                    .Columns(8).Text = "del04"
                    .Columns.Add(New ColumnHeader)
                    .Columns(9).Text = "del05"
                    .Columns.Add(New ColumnHeader)
                    .Columns(10).Text = "del06"
                    .Columns.Add(New ColumnHeader)
                    .Columns(11).Text = "del07"
                    .Columns.Add(New ColumnHeader)
                    .Columns(12).Text = "del08"
                    .Columns.Add(New ColumnHeader)
                    .Columns(13).Text = "del09"
                    .Columns.Add(New ColumnHeader)
                    .Columns(14).Text = "del10"
                End With

                If dtTemp Is Nothing Then Exit Sub

                Dim itmPingResult As ListViewItem
                Dim m_dr As DataRow
                For Each m_dr In dtTemp.Rows
                    itmPingResult = New ListViewItem(m_dr.Item("spPacketSize").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spAvgDelay").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spMaxDelay").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spMinDelay").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spErrorCt").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel01").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel02").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel03").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel04").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel05").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel06").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel07").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel08").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel09").ToString)
                    itmPingResult.SubItems.Add(m_dr.Item("spDel10").ToString)
                    dlvControl.Items.Add(itmPingResult)
                Next m_dr


            Catch err As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(err, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try
        End Sub



    End Class


    Public Class IcmpPingResults
        ' as array of ping results that can be used to
        ' feed the data list view control
        Public Structure stcPingResult
            Public pingIndex As Integer
            Public pingName As String
            Public pingAddress As String
            Public pingTime As Int32
            Public pingDataLen As Integer
            Public pingResult As String
        End Structure

        Public dtPingResult As System.Data.DataTable

        Private m_pingIndex As Int16
        Public Property pingIndex() As Int16
            Get
                pingIndex = m_pingIndex
            End Get
            Set(ByVal value As Int16)
                m_pingIndex = value
            End Set
        End Property

        Private m_pingName As String
        Public Property pingName() As String
            Get
                pingName = m_pingName
            End Get
            Set(ByVal value As String)
                m_pingName = value
            End Set
        End Property

        Private m_pingAddress As String
        Public Property pingAddress() As String
            Get
                pingAddress = m_pingAddress
            End Get
            Set(ByVal value As String)
                m_pingAddress = value
            End Set
        End Property

        Private m_pingTime As Int32
        Public Property pingTime() As Int32
            Get
                pingTime = m_pingTime
            End Get
            Set(ByVal value As Int32)
                m_pingTime = value
            End Set
        End Property

        Private m_pingDataLen As Integer
        Public Property pingDataLen() As Integer
            Get
                pingDataLen = m_pingDataLen
            End Get
            Set(ByVal value As Integer)
                m_pingDataLen = value
            End Set
        End Property

        Private m_pingResult As String
        Public Property pingResult() As String
            Get
                pingResult = m_pingResult
            End Get
            Set(ByVal value As String)
                m_pingResult = value
            End Set
        End Property

        Private m_colPingResults As Collection(Of stcPingResult)
        Public Property pColPingResults() As Collection(Of stcPingResult)
            Get
                If m_colPingResults Is Nothing Then
                    m_colPingResults = New Collection(Of stcPingResult)
                End If
                pColPingResults = m_colPingResults
            End Get
            Set(ByVal value As Collection(Of stcPingResult))
                m_colPingResults = value
            End Set
        End Property


        Public Sub Add(ByVal resultPing As stcPingResult)

            pColPingResults.Add(resultPing)

        End Sub

        Public Function Count() As Integer

            Return pColPingResults.Count

        End Function

        Public Sub Clear()

            If m_colPingResults Is Nothing Then
                m_colPingResults = New Collection(Of stcPingResult)
            Else
                m_colPingResults.Clear()
            End If

        End Sub

        Public Sub CreateTableColumns(ByRef tempTable As DataTable)

            tempTable.TableName = "tblIcmpResults"

            Try
                ' create the table field definitions 

                Dim dcPingIndex As New System.Data.DataColumn
                dcPingIndex.ColumnName = "pingIndex"
                dcPingIndex.DataType = Type.GetType("System.Int16")
                tempTable.Columns.Add(dcPingIndex)

                Dim dcPingName As New System.Data.DataColumn
                dcPingName.ColumnName = "pingName"
                dcPingName.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dcPingName)

                Dim dcPingAddress As New System.Data.DataColumn
                dcPingAddress.ColumnName = "pingAddress"
                dcPingAddress.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dcPingAddress)

                Dim dcPingTime As New System.Data.DataColumn
                dcPingTime.ColumnName = "pingTime"
                dcPingTime.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dcPingTime)

                Dim dcPingDataLen As New System.Data.DataColumn
                dcPingDataLen.ColumnName = "pingDataLen"
                dcPingDataLen.DataType = Type.GetType("System.Int16")
                tempTable.Columns.Add(dcPingDataLen)

                Dim dcPingResult As New System.Data.DataColumn
                dcPingResult.ColumnName = "pingResult"
                dcPingResult.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dcPingResult)



            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub


        Public Sub loadTable(ByRef tempTable As System.Data.DataTable)
            Try

                ' fill the table

                Dim stcResult As stcPingResult
                Dim m_dr As DataRow
                For Each stcResult In m_colPingResults
                    With stcResult
                        m_dr = tempTable.NewRow
                        m_dr.Item("pingIndex") = .pingIndex
                        m_dr.Item("pingName") = .pingName
                        m_dr.Item("pingAddress") = .pingAddress
                        m_dr.Item("pingTime") = .pingTime
                        m_dr.Item("pingDataLen") = .pingDataLen
                        m_dr.Item("pingResult") = .pingResult
                        tempTable.Rows.Add(m_dr)
                    End With
                Next stcResult

            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub

        '
        '
        '
        Public Sub buildReportTable()

            dtPingResult = Nothing
            dtPingResult = New System.Data.DataTable
            CreateTableColumns(dtPingResult)
            loadTable(dtPingResult)

        End Sub

        '
        '
        '
        Public Sub loadDLVPingResults _
            (ByRef dlvControl As System.Windows.Forms.ListView, _
             Optional ByVal dtTemp As System.Data.DataTable = Nothing)

            Try

                dlvControl.Clear()
                dlvControl.Columns.Clear()

                With dlvControl
                    .Columns.Add(New ColumnHeader)
                    .Columns(0).Text = "Index"
                    .Columns.Add(New ColumnHeader)
                    .Columns(1).Text = "Device"
                    .Columns.Add(New ColumnHeader)
                    .Columns(2).Text = "Address"
                    .Columns.Add(New ColumnHeader)
                    .Columns(3).Text = "Time(ms)"
                    .Columns.Add(New ColumnHeader)
                    .Columns(4).Text = "DataLen"
                    .Columns.Add(New ColumnHeader)
                    .Columns(5).Text = "Result"
                End With

                dlvControl.View = View.Details

                If dtTemp Is Nothing Then Exit Sub

                Dim itmPingResult As ListViewItem
                Dim m_dr As DataRow
                If dtTemp Is Nothing Then
                Else
                    For Each m_dr In dtTemp.Rows
                        itmPingResult = New ListViewItem(m_dr.Item("pingIndex").ToString)
                        itmPingResult.SubItems.Add(m_dr.Item("pingName").ToString)
                        itmPingResult.SubItems.Add(m_dr.Item("pingAddress").ToString)
                        itmPingResult.SubItems.Add(m_dr.Item("pingTime").ToString)
                        itmPingResult.SubItems.Add(m_dr.Item("pingDataLen").ToString)
                        itmPingResult.SubItems.Add(m_dr.Item("pingResult").ToString)
                        dlvControl.Items.Add(itmPingResult)
                    Next m_dr
                End If

                dlvControl.Refresh()

            Catch err As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(err, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub




        Public Sub New()

            pColPingResults = New Collection(Of stcPingResult)
            dtPingResult = New System.Data.DataTable

        End Sub


    End Class


    Public Class IcmpTraceRouteResult

        Public Structure stcTraceRouteResult
            Public trHop As Integer
            Public trTripTime As Int32
            Public trHostIP As String
            Public trHostName As String
            Public trErrorStatus As String
            Public trSecondStatus As String
        End Structure


        Public dtTraceRoute As System.Data.DataTable

        Private m_trHop As Int16
        Public Property trHop() As Int16
            Get
                trHop = m_trHop
            End Get
            Set(ByVal value As Int16)
                m_trHop = value
            End Set
        End Property

        Private m_trTripTime As Int32
        Public Property trTripTime() As Int32
            Get
                trTripTime = m_trTripTime
            End Get
            Set(ByVal value As Int32)
                m_trTripTime = value
            End Set
        End Property

        Private m_trHostIp As String
        Public Property trHostIp() As String
            Get
                trHostIp = m_trHostIp
            End Get
            Set(ByVal value As String)
                m_trHostIp = value
            End Set
        End Property

        Private m_trHostName As String
        Public Property trHostName() As String
            Get
                trHostName = m_trHostName
            End Get
            Set(ByVal value As String)
                m_trHostName = value
            End Set
        End Property

        Private m_trErrorStatus As String
        Public Property trErrorStatus() As String
            Get
                trErrorStatus = m_trErrorStatus
            End Get
            Set(ByVal value As String)
                m_trErrorStatus = value
            End Set
        End Property

        Private m_trSecondStatus As String
        Public Property trSecondStatus() As String
            Get
                trSecondStatus = m_trSecondStatus
            End Get
            Set(ByVal value As String)
                m_trSecondStatus = value
            End Set
        End Property

        Private m_colTraceResults As Collection(Of stcTraceRouteResult)
        Public Property colTraceResults() As Collection(Of stcTraceRouteResult)
            Get
                If m_colTraceResults Is Nothing Then
                    m_colTraceResults = New Collection(Of stcTraceRouteResult)
                End If
                colTraceResults = m_colTraceResults
            End Get
            Set(ByVal value As Collection(Of stcTraceRouteResult))
                m_colTraceResults = value
            End Set
        End Property

        Public Sub Add(ByVal trResult As stcTraceRouteResult)
            colTraceResults.Add(trResult)
        End Sub

        Public Sub Clear()
            If Not (colTraceResults Is Nothing) Then
                colTraceResults.Clear()
            Else
                colTraceResults = New Collection(Of stcTraceRouteResult)
            End If
        End Sub

        '
        '
        '
        Public Sub CreateTableColumns(ByRef tempTable As DataTable)


            tempTable.TableName = "tblTraceRouteResults"

            Try

                Dim dctrHop As New System.Data.DataColumn
                dctrHop.ColumnName = "trHop"
                dctrHop.DataType = Type.GetType("System.Int16")
                tempTable.Columns.Add(dctrHop)

                Dim dctrTripTime As New System.Data.DataColumn
                dctrTripTime.ColumnName = "trTripTime"
                dctrTripTime.DataType = Type.GetType("System.Int32")
                tempTable.Columns.Add(dctrTripTime)

                Dim dctrHostIp As New System.Data.DataColumn
                dctrHostIp.ColumnName = "trHostIp"
                dctrHostIp.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dctrHostIp)

                Dim dctrHostName As New System.Data.DataColumn
                dctrHostName.ColumnName = "trHostName"
                dctrHostName.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dctrHostName)

                Dim dctrErrorStatus As New System.Data.DataColumn
                dctrErrorStatus.ColumnName = "trErrorStatus"
                dctrErrorStatus.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dctrErrorStatus)

                Dim dctrSecondStatus As New System.Data.DataColumn
                dctrSecondStatus.ColumnName = "trSecondStatus"
                dctrSecondStatus.DataType = Type.GetType("System.String")
                tempTable.Columns.Add(dctrSecondStatus)

            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try


        End Sub

        '
        ' move the collection to an output table
        '
        Public Sub loadTable(ByRef tempTable As System.Data.DataTable)

            Try

                Dim stcResult As stcTraceRouteResult
                Dim m_dr As DataRow
                For Each stcResult In colTraceResults
                    With stcResult
                        m_dr = tempTable.NewRow
                        m_dr.Item("trHop") = .trHop
                        m_dr.Item("trTripTime") = .trTripTime
                        m_dr.Item("trHostIp") = .trHostIP
                        m_dr.Item("trHostName") = .trHostName
                        m_dr.Item("trErrorStatus") = .trErrorStatus
                        m_dr.Item("trSecondStatus") = .trSecondStatus

                        tempTable.Rows.Add(m_dr)
                    End With
                Next stcResult


            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub

        '
        '
        '
        Public Sub buildReportTable()

            dtTraceRoute = Nothing
            dtTraceRoute = New System.Data.DataTable
            CreateTableColumns(dtTraceRoute)
            loadTable(dtTraceRoute)

        End Sub


        '
        ' pass in a listview control and optionally a datatable to fill the information in
        '
        Public Sub loadDlvTraceRoute _
            (ByRef dlvControl As System.Windows.Forms.ListView, _
             Optional ByVal dtTemp As System.Data.DataTable = Nothing)

            Try


                dlvControl.Clear()
                dlvControl.Columns.Clear()
                dlvControl.View = View.Details

                With dlvControl
                    .Columns.Add(New ColumnHeader)
                    .Columns(0).Text = "Hop#"
                    .Columns.Add(New ColumnHeader)
                    .Columns(1).Text = "TripTime"
                    .Columns.Add(New ColumnHeader)
                    .Columns(2).Text = "HostIP"
                    .Columns.Add(New ColumnHeader)
                    .Columns(3).Text = "HostName"
                    .Columns.Add(New ColumnHeader)
                    .Columns(4).Text = "ErrorStatus"
                    .Columns.Add(New ColumnHeader)
                    .Columns(5).Text = "SecondStatus"
                End With

                ' if no data transferred get out
                If dtTemp Is Nothing Then Exit Sub

                Dim itmTrace As ListViewItem
                Dim m_dr As DataRow
                If 0 < dtTemp.Rows.Count Then
                    For Each m_dr In dtTemp.Rows
                        itmTrace = New ListViewItem(m_dr.Item("trHop").ToString)
                        itmTrace.SubItems.Add(m_dr.Item("trTripTime").ToString)
                        itmTrace.SubItems.Add(m_dr.Item("trHostIp").ToString)
                        itmTrace.SubItems.Add(m_dr.Item("trHostName").ToString)
                        itmTrace.SubItems.Add(m_dr.Item("trErrorStatus").ToString)
                        itmTrace.SubItems.Add(m_dr.Item("trSecondStatus").ToString)
                        dlvControl.Items.Add(itmTrace)
                    Next
                End If

            Catch ex As Exception
                Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
                If (rethrow) Then
                    Throw
                End If
            End Try

        End Sub



        Public Sub New()
            colTraceResults = New Collection(Of stcTraceRouteResult)
            dtTraceRoute = New System.Data.DataTable
            CreateTableColumns(dtTraceRoute)
        End Sub

    End Class


    Public Class ICMPPingDevice


        Private m_devAddress As String
        Public Property devAddress() As String
            Get
                devAddress = m_devAddress
            End Get
            Set(ByVal value As String)
                m_devAddress = value
            End Set
        End Property

        Private m_devFrameSize As Int16
        Public Property devFrameSize() As Int16
            Get
                devFrameSize = m_devFrameSize
            End Get
            Set(ByVal value As Int16)
                m_devFrameSize = value
            End Set
        End Property

        Private m_devTTL As Int16
        Public Property devTTL() As Int16
            Get
                devTTL = m_devTTL
            End Get
            Set(ByVal value As Int16)
                m_devTTL = value
            End Set
        End Property

        Private m_devTimeout As Int32
        Public Property devTimeout() As Int32
            Get
                devTimeout = m_devTimeout
            End Get
            Set(ByVal value As Int32)
                m_devTimeout = value
            End Set
        End Property

        Private m_devPingLimit As Int16
        Public Property devPingLimit() As Int16
            Get
                devPingLimit = m_devPingLimit
            End Get
            Set(ByVal value As Int16)
                m_devPingLimit = m_devPingLimit
            End Set
        End Property

        Private m_devPingSubmitted As Int16
        Public Property devPingSubmitted() As Int16
            Get
                devPingSubmitted = m_devPingSubmitted
            End Get
            Set(ByVal value As Int16)
                m_devPingSubmitted = value
            End Set
        End Property

        Private m_devState As String
        Public Property devState() As String
            Get
                devState = m_devState
            End Get
            Set(ByVal value As String)
                m_devState = value
            End Set
        End Property

        Private m_devReverseLookup As Boolean
        Public Property devReverseLookup() As Boolean
            Get
                devReverseLookup = m_devReverseLookup
            End Get
            Set(ByVal value As Boolean)
                m_devReverseLookup = value
            End Set
        End Property

        Private m_devBuildBuffer As Boolean
        Public Property devBuildBuffer() As Boolean
            Get
                devBuildBuffer = m_devBuildBuffer
            End Get
            Set(ByVal value As Boolean)
                m_devBuildBuffer = value
            End Set
        End Property

        Private m_devFragment As Boolean
        Public Property devFragment() As Boolean
            Get
                devFragment = m_devFragment
            End Get
            Set(ByVal value As Boolean)
                m_devFragment = value
            End Set
        End Property


        Public Sub New()
            initPingDevice()
        End Sub

        Public Sub initPingDevice()

        End Sub


    End Class





End Class
